******SET YOUR DIRECTORY to ...\replication



////////////////////////////////////////////////////////////////////////////////
///PANEL A
////////////////////////////////////////////////////////////////////////////////

clear all
set more off

use "finaldata\final_cc_data.dta", clear

set matsize 2000
drop if fipsplace_00==.
xtset fipsplace_00 year

drop if year>1991

*Create instrument and outcome
g good_soil = (ph1_plc_wtm_wtm_0_r>=6.8 & ph1_plc_wtm_wtm_0_r<=7.7)
gen inter_badtetra=(1-good_soil)*tetra_corr
g incomeCC_incomeMSA = cincome / income
g lexpenses_highway_cc = ln( expenses_highway_cc)

*Create per capita variables
gen vc_pc=totnpcc_cc_offenses_vc*1000

*Cluster variables
gen cdivcodeyear=cdivcode*year
gen cregcodeyear=cregcode*year

*Label variables
label var vc_pc "Violent crime"
label var inter_badtetra "High LB x Lead"
label var incomeCC_incomeMSA "Income CC / MSA"
label var lexpenses_highway_cc "ln(Expend. Hways)"
label var cdivcodeyear "Census Division Code x Year"
label var cregcodeyear "Census Region Code x Year"

***Regressions
*Perc black CC
ivreghdfe cpctblk (vc_pc = inter_badtetra), abs(fipsplace_00 year cregcode#year) cluster(cregcodeyear)
local ff= string(round(e(cdf),.01) , "%9.2f")

*Income CC / Income MSA
ivreghdfe incomeCC_incomeMSA (vc_pc = inter_badtetra), abs(fipsplace_00 year cregcode#year) cluster(cregcodeyear)
local ff= string(round(e(cdf),.01) , "%9.2f")

*Gini
ivreghdfe ginih (vc_pc = inter_badtetra), abs(fipsplace_00 year cregcode#year) cluster(cregcodeyear)
local ff= string(round(e(cdf),.01) , "%9.2f")

*Highways
ivreghdfe racc (vc_pc = inter_badtetra), abs(fipsplace_00 year cregcode#year) cluster(cregcodeyear)
local ff= string(round(e(cdf),.01) , "%9.2f")

*Highways expenditure
ivreghdfe lexpenses_highway_cc (vc_pc = inter_badtetra), absorb(fipsplace_00 year cregcode#year) cluster(cregcodeyear)
local ff= string(round(e(cdf),.01) , "%9.2f")

*Pub. transportation
ivreghdfe pubtrans (vc_pc = inter_badtetra), abs(fipsplace_00 year cregcode#year) cluster(cregcodeyear)
local ff= string(round(e(cdf),.01) , "%9.2f")



////////////////////////////////////////////////////////////////////////////////
///PANEL B
////////////////////////////////////////////////////////////////////////////////
clear all
set more off

use "finaldata\final_cc_data.dta", clear

drop if fipsplace_00==.
xtset fipsplace_00 year

drop if year>1991

***Merge with employment decentralization
merge 1:1 fipsplace_00 year using "finaldata\data_cbp.dta"
drop _merge

drop if fipsplace_00==.
xtset fipsplace_00 year

*Create instrument
g good_soil = (ph1_plc_wtm_wtm_0_r>=6.8 & ph1_plc_wtm_wtm_0_r<=7.7)
gen inter_goodtetra=good_soil*tetra_corr
gen inter_badtetra=(1-good_soil)*tetra_corr

*Create independent variable
gen vc_pc=totnpcc_cc_offenses_vc*1000

*Cluster variables
egen cdivcodeyear=group(cdivcode year)

*Label variables
label var vc_pc "Violent crime"
label var inter_goodtetra "Low LB x Lead"
label var perc_empl_ctycc_sic0 "Sh. employment All"
label var perc_empl_ctycc_sic20 "Sh. employment Manuf"
label var perc_empl_ctycc_sic50 "Sh. employment Wholesale"
label var perc_empl_ctycc_sic52 "Sh. employment Retail"
label var perc_empl_ctycc_sic60 "Sh. employment Finance"
label var perc_empl_ctycc_sic70 "Sh. employment Other serv"

***Regressions
*All sectors
ivreghdfe perc_empl_ctycc_sic0 (vc_pc=inter_badtetra), abs(fipsplace_00 year cdivcode#year)  cluster(cdivcodeyear)
local ff= string(round(e(cdf),.01) , "%9.2f")
*Manufacturing
ivreghdfe perc_empl_ctycc_sic20 (vc_pc=inter_badtetra), abs(fipsplace_00 year cdivcode#year)  cluster(cdivcodeyear)
local ff= string(round(e(cdf),.01) , "%9.2f")
*Wholesale
ivreghdfe perc_empl_ctycc_sic50 (vc_pc = inter_badtetra), abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
local ff= string(round(e(cdf),.01) , "%9.2f")
*Retail
ivreghdfe perc_empl_ctycc_sic52 (vc_pc = inter_badtetra), abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
local ff= string(round(e(cdf),.01) , "%9.2f")
*Finance
ivreghdfe perc_empl_ctycc_sic60 (vc_pc=inter_badtetra), abs(fipsplace_00 year cdivcode#year)  cluster(cdivcodeyear)
local ff= string(round(e(cdf),.01) , "%9.2f")
*Other services
ivreghdfe perc_empl_ctycc_sic70 (vc_pc = inter_badtetra), abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
local ff= string(round(e(cdf),.01) , "%9.2f")
